#!/usr/bin/env python3
"""
清理数据目录中的多余文件
"""

import os
import shutil
from pathlib import Path

def cleanup_backup_files(data_dir: Path):
    """清理备份文件"""
    backup_files = []
    for root, dirs, files in os.walk(data_dir):
        for file in files:
            if file.endswith('.backup'):
                backup_files.append(os.path.join(root, file))
    
    print(f"找到 {len(backup_files)} 个备份文件")
    for f in backup_files:
        try:
            os.remove(f)
            print(f"  删除: {f}")
        except Exception as e:
            print(f"  删除失败 {f}: {e}")
    
    return len(backup_files)

def main():
    data_dir = Path("data/processed/segmentation")
    if not data_dir.exists():
        print(f"数据目录不存在: {data_dir}")
        return
    
    print("开始清理数据目录...")
    cleaned = cleanup_backup_files(data_dir)
    print(f"清理完成，共删除 {cleaned} 个备份文件")

if __name__ == "__main__":
    main()

